package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.common.dto.SaveMealDto;
import com.itheima.reggie.common.dto.SetmealDishFrontDto;
import com.itheima.reggie.common.dto.SetmealListDto;
import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.entity.Setmeal;
import com.itheima.reggie.entity.SetmealDish;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: Liu
 * @date: 2022/03/01
 * @time: 15:43
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {
    @Autowired
    SetmealService setmealService;


    @PostMapping
    public R<String> save(@RequestBody SaveMealDto saveMealDto) {
        return setmealService.add(saveMealDto);
    }

    @GetMapping("/page")
    private R<Page<SetmealListDto>> pageBySetmeal(Long page, Long pageSize, String name) {
        return setmealService.pageBySetmeal(page, pageSize, name);
    }

    @DeleteMapping
    public R<String> deleteById(@RequestParam List<Long> ids) {
        return setmealService.deleteById(ids);
    }

    @GetMapping("{id}")
    public R<SaveMealDto> findByIdSetmeal(@PathVariable Long id) {
        return setmealService.findByIdSetmeal(id);
    }

    @PutMapping
    public R<String> updateSetmeal(@RequestBody SaveMealDto saveMealDto) {
        return setmealService.updateSetmeal(saveMealDto);
    }

    @PostMapping("/status/0")
    public R<String> stopSell(@RequestParam List<Long> ids) {
        return setmealService.stopSell(ids);
    }

    @PostMapping("/status/1")
    public R<String> startSell(@RequestParam List<Long> ids) {
        return setmealService.startSell(ids);
    }


    @GetMapping("/list")
    public R<List<Setmeal>> getSetmealList(Long categoryId, Integer status) {
        return setmealService.getSetmealList(categoryId, status);
    }

    @GetMapping("/dish/{id}")
    public R<List<Dish>> getSetmealDishList(@PathVariable Long id) {
        return setmealService.getSetmealDishList(id);
    }
}
